package com.ruoyi.web.controller.book;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.business.CmBookInfoBusiness;
import com.ruoyi.module.domain.BookInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 图书西信息Controller
 *
 * @author ruoyi
 * @date 2022-04-13
 */
@RestController
@RequestMapping("/system/info")
@RequiredArgsConstructor
public class CmBookInfoController extends BaseController {
    private final CmBookInfoBusiness cmBookInfoBusiness;

    /**
     * 查询图书西信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(String spbs,
                              String tm,
                              String sm,
                              String zyz) {
        startPage();
        List<BookInfo> list = cmBookInfoBusiness.selectCmBookInfoList(spbs, tm, sm, zyz);
        return getDataTable(list);
    }

    /**
     * 获取图书西信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cmBookInfoBusiness.selectCmBookInfoById(id));
    }

    /**
     * 新增图书西信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "图书西信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookInfo cmBookInfo) {
        return toAjax(cmBookInfoBusiness.insertCmBookInfo(cmBookInfo));
    }

    /**
     * 修改图书西信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "图书西信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookInfo cmBookInfo) {
        return toAjax(cmBookInfoBusiness.updateCmBookInfo(cmBookInfo));
    }

    /**
     * 删除图书西信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "图书西信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(cmBookInfoBusiness.deleteCmBookInfoByIds(ids));
    }
}
